package org.or5e.oss.ws.helper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.or5e.oss.core.BaseObject;
import org.or5e.oss.core.DBUtils;
import org.or5e.oss.ws.UserInfo;

public class SignInServiceHelper extends BaseObject {
	public static final UserInfo getUserAuthentication(String userKey, String userPass) {
		Connection _connection = DBUtils.getDBUtils().getConnection();
		UserInfo userInfo = null; 
		PreparedStatement _statement = null;
		ResultSet _rSet = null;

		try {
			_statement = _connection.prepareStatement(QueryConstants.LOGIN_QUERY);
			_statement.setString(1, userKey);
			_statement.setString(2, userPass);

			_rSet = _statement.executeQuery();
			while(_rSet.next()) {
				userInfo = new UserInfo();
				userInfo.setUserName(_rSet.getString("userName"));
				userInfo.setUserStatus(_rSet.getBoolean("userStatus"));
				userInfo.setUserID(_rSet.getString("userID"));
				userInfo.setSecurityToken("#admin#FullAccess#");
			}
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally {
			try {
				_rSet.close();
				_statement.close();
			} 
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return userInfo;
	}
	
	@Override
	public String getName() {
		return "SignInServiceHelper";
	}

}
